Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:01:15+00:00 2026-06-08T00:01:15+00:00

I want to convert pdfs to image files within appengine. Ideally I would upload

  • 0

I want to convert pdfs to image files within appengine. Ideally I would upload the pdf as a blob and store both the pdf and an image of the pdf. The conversion could also be done at a different time (taskqueue).

I have not found any working samples or good documentation of doing this.
The official documentation is here. Here is my implementation on my upload servlet.

@SuppressWarnings("serial")
public class UploadBlobServlet extends HttpServlet {

  private static final Logger log = Logger.getLogger(UploadBlobServlet.class.getName());

public void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {

    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
    Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
    BlobKey blobKey = blobs.get("data");
    log.log(Level.WARNING,"blobKey: "+blobKey.getKeyString());



        if (blobKey != null) {
        resp.getWriter().println(blobKey.getKeyString());

        BlobstoreInputStream in=new BlobstoreInputStream(blobKey);
        byte[] b = IOUtils.toByteArray(is);
      //  try{
            in.read(b);
            Asset asset = new Asset(
                    "application/pdf", b, "testfile.pdf");
                Document document = new Document(asset);
                Conversion conversion = new Conversion(document, "image/png");

                ConversionService service =
                    ConversionServiceFactory.getConversionService();
                ConversionResult result = service.convert(conversion);

                if (result.success()) {
                  // Note: in most cases, we will return data all in one asset,
                  // except that we return multiple assets for multi-page images.
                FileService fileService=FileServiceFactory.getFileService(); 
                for (Asset ass : result.getOutputDoc().getAssets()) {
                    AppEngineFile file=fileService.createNewBlobFile("image/png", "testfile.png");
                    FileWriteChannel writeChannel=fileService.openWriteChannel(file, false);
                    writeChannel.write(ByteBuffer.wrap(b));
                    writeChannel.closeFinally();
                  }
                } else {
                    log.log(Level.WARNING,"error");

                }

Update: Have added byte[]=IOUtils.toByteArray(is); and still getting a NPE…

I am also curious as to the quality of the conversion if anyone has experience.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:01:16+00:00Added an answer on June 8, 2026 at 12:01 am

    Here is the working code to receive an upload pdf and convert it to a png using the Conversion api. The upload is completed with a multi-part post to an upload url must be obtained through:

         String url=blobstoreService.createUploadUrl("/upload");
    

    Just place this code in a servlet and map it to “upload” in your web.xml.

    The Conversion is good quality, however I did notice just a little blurriness around text. In my case the png was about 25% larger.

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
    
        BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
        Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
        BlobKey blobKey = blobs.get("data");
    
    
    
            if (blobKey != null) {
            resp.getWriter().println(blobKey.getKeyString());
            BlobstoreInputStream in=new BlobstoreInputStream(blobKey);
    
            byte[] b = IOUtils.toByteArray(in);
            if(b!=null){
                log.log(Level.WARNING,"blobsize: "+b.length);
            }else{
                log.log(Level.WARNING,"b is null");
    
            }
                in.read(b);
                Asset asset = new Asset(
                        "application/pdf", b, "testfile.pdf");
                    Document document = new Document(asset);
                    Conversion conversion = new Conversion(document, "image/png");
    
                    ConversionService service =
                        ConversionServiceFactory.getConversionService();
                    ConversionResult result = service.convert(conversion);
    
                    if (result.success()) {
                      // Note: in most cases, we will return data all in one asset,
                      // except that we return multiple assets for multi-page images.
                    FileService fileService=FileServiceFactory.getFileService(); 
                    for (Asset ass : result.getOutputDoc().getAssets()) {
                        AppEngineFile file=fileService.createNewBlobFile("image/png", "test3file.png");
                        FileWriteChannel writeChannel=fileService.openWriteChannel(file, true);
                        writeChannel.write(ByteBuffer.wrap(ass.getData()));
    
                        writeChannel.closeFinally();
                      }
                    } else {
                        log.log(Level.WARNING,"error");
    
                    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I to want convert PDF pages into an image (PNG,JPEG/JPG or GIF). I want
I want to convert a number to hex and store the result in a
I want to convert a data string into a timestamp (which would include the
i want to display the pdf files to the users in my site, with
I want to write a python script to convert PNG's into 2-page pdfs (i.e.
I want convert a File(.jpg image file) into a txt file(ASCII code) now, I
i want convert image into byte array in php.actually i am accessing web service
i want to convert my rgb image into a ycbcr image and vice versa
I am getting a pdf in byte array . I want to convert just
I want to convert a string to formatted text in C# in WPF application,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.