Skip to main content
Participating Frequently
January 15, 2018
Answered

Easiest way to draw all annotations with PDPageDrawContentsToMemory?

  • January 15, 2018
  • 1 reply
  • 1093 views

I am currently trying to draw a PDF (as well as the text annotations) using PDPageDrawContentsToMemory, but I'm running into problems.This  [https://forums.adobe.com/thread/827380​] thread seems to suggest text annotations will draw if kPDPageIsPrinting and kPDPageUseAnnotFaces are set as drawFlags, but this doesn't appear to be working when I try it. The PDF draws to the screen, but without the annotations. What am I missing here? Thanks

Relevant code snippet:

"

...

csAtom = ASAtomFromString("DeviceRGB");

drawFlags = kPDPageIsPrinting | kPDPageUseAnnotFaces |  kPDPageSwapComponents;

smoothFlags = kPDPageDrawSmoothText | kPDPageDrawSmoothLineArt | kPDPageDrawSmoothImage;

PDPageDrawContentsToMemory( pdPage, drawFlags, &matrix, pASInvRect, smoothFlags, csAtom, 8, &bRect, (char*)pBits, bitsSize, nil, nil);

"

This topic has been closed for replies.
Correct answer lrosenth

I do not see a way to upload files in this thread, so I've uploaded some some screenshots from a test PDF I made containing only this green square and a single test annotation. The first image shows my desired result (source: Acrobat Reader DC). Ideally, I'd like the annotations to just statically draw on top of the PDF. The second image shows the output from my drawing code. Even though there is an annotation symbol, the contents of the annotation are not drawn. Does "rendering" the annotation merely mean that the little annotation icons are drawn, or is it supposed to also display the contents of the annotations?


In the case of a PopUp annotation (which is what you are using there), the only thing relevant to printing/rendering is the balloon icon, since that is what is present as the appearance (AP) of the annotation. The text info is stored in a separate, appearance-less, annotation, which is why it isn’t rendered.

1 reply

lrosenth
Adobe Employee
Adobe Employee
January 16, 2018

Only use isPrinting if you are outputting to CMYK. Here is some code from one of Adobe’s samples that I happened to have handy

// Consider exposing setting these flags in future versions

mDrawFlags = kPDPageDoLazyErase | kPDPageUseAnnotFaces;

if (eColorSpace == kDeviceCMYK) {

mDrawFlags |= kPDPageIsPrinting;

}

mSmoothFlags = kPDPageDrawSmoothText | kPDPageDrawSmoothLineArt | kPDPageDrawSmoothImage;

Also, I would strongly recommend that you use PDPageDrawContentsToMemoryEx (note the Ex), which is the newer and more powerful version of the routine.

Participating Frequently
January 17, 2018

I've refactored the code to use PDPageDrawContentsToMemoryEx instead, but I'm still not drawing the text and link annotations as I'd like. According to the documentation for kPDPageUseAnnotFaces , "If set, it draws annotations that have a default face, such as the visible fields in an Acrobat form. Text and link annotations are not drawn." How then, are text and link annotations drawn when outputting to RGB? Is there some combinations of flags that must be set? Or some other prep work? In the thread I linked in my original post, you said, "Also do "isprinting"" as a way to draw text annotations, but since I'm outputting to RGB (and not CMYK), you also say this won't work. Thanks again for the advice.

My current set up:

...

ASCab flags = ASCabNew();

ASCabPutBool(flags, kPDPageUseAnnotFacesStr, true);

ASCabPutBool(flags, kPDPageDoLazyEraseStr, true);

ASCabPutBool(flags, kPDPageDrawSmoothTextStr, true);

ASCabPutBool(flags, kPDPageDrawSmoothLineArtStr, true);

ASCabPutBool(flags, kPDPageDrawSmoothImageStr, true);

PDPageDrawContentsToMemoryEx(pdPage, flags, &doubleMatrix, &updateRect, csAtom, 8, &doubleRect, (char*)pBits, bitsSize, nil, nil);

lrosenth
Adobe Employee
Adobe Employee
January 17, 2018

As long as the annotations in question have existing appearances, they will be rendered.

If you want to share a PDF that isn’t doing the right thing with the code you posted, I will be happy to look into it.

I also confirmed that isPrinting isn’t what you want here = since you aren’t printing (and it does change some of the flags on annotation rendering)