Professional Web Applications Themes

Shrinking of PDF Page - Adobe Acrobat SDK

Hi All, I am looking for an API through which I am able to shrink a PDF page. For example I want an A3 page to be converted to A4 without loss of any content.Please let me know is there any option available for doing the same apart from printing the page to a new file. Looking forward to your help....

  1. #1

    Default Shrinking of PDF Page

    Hi All,

    I am looking for an API through which I am able to shrink a PDF page. For example I want an A3 page to be converted to A4 without loss of any content.Please let me know is there any option available for doing the same apart from printing the page to a new file.

    Looking forward to your help.
    Rajeshrv@adobeforums.com Guest

  2. #2

    Default Re: Shrinking of PDF Page

    Rajeshrv,

    The MediaBox controls the page size for each page. You can change this to control the physical size of the page, and then add a transformation matrix to the content stream for that page that will scale the content to the appropriate size without losing any data.
    PDL@adobeforums.com Guest

  3. #3

    Default Re: Shrinking of PDF Page

    Hi PDL,

    Thank you for your inofrmation.
    As you said I changed the mediabox and i am using the following code to get the content stream.

    CosObj cosPage = PDPageGetCosObj(objPDPage);
    if(CosObjGetType(cosPage) == CosDict)
    {
    cosContent = CosDictGet(cosPage,ASAtomFromString("Contents"));
    }

    after this could you please help me in adding the transformation matrix.

    Thank you.
    Rajeshrv@adobeforums.com Guest

  4. #4

    Default Re: Shrinking of PDF Page

    Rajeshrv,
    The ActionHandler sample from the SDK uses a lot of cos level manipulation. It is a good frame of reference to start from. The following code is from that sample and shows how to set an arbitrary string into a CosDict, which you could probably use to set the value of the content stream ...

    // Delete the existing help text from the dictionary.
    CosDictRemoveKeyString (oActionDict, STR_KEY);

    // Insert the help text into the dictionary.
    cosDoc = PDDocGetCosDoc (AVDocGetPDDoc(doc));

    ASTArraySize len;
    char* text = NULL;
    text = ASTextGetPDTextCopy (currentText, &len);
    oHelpString = CosNewString (cosDoc, false, text, len);
    ASfree(text);
    CosDictPutKeyString (oActionDict, STR_KEY, oHelpString);

    The construction of a transformation matrix in a content stream is explained in the PDF Reference doent - Chapter 4.2 You simply need to add a cm operator at the beginning of the existing stream. You will probably have to play with the values to get the scaling right.

    For answers more specific than this you should probably shell out the cash for a developer support case with the Adobe support folks.
    NiceNix@adobeforums.com Guest

  5. #5

    Default Re: Shrinking of PDF Page

    Hi NiceNix
    thanks for your help.

    I have done the page shrinking using the following code, but after the execution some content loss is there in the page.

    CosObj content, newContent;
    ASStm objContentStream, objNewStream;
    char* charMatrix = "q 0.5 0 0 1 0 0 cm \r";
    CosObj cosPage = PDPageGetCosObj(objPDPage);
    ASInt32 iSize = strlen(charMatrix);
    if(CosObjGetType(cosPage) == CosDict)
    {
    content = CosDictGet(cosPage,atom);
    if(CosObjGetType(content) == CosStream)
    {
    ASInt32 iLength = CosStreamLength(content);
    inBuffer = (char*)ASmalloc(iLength);
    outBuffer = (char*)ASmalloc(iLength + iSize);
    objContentStream = CosStreamOpenStm(content, cosOpenFiltered);
    ASInt32 bytesRead = ASStmRead(inBuffer, iLength, 1, objContentStream);
    memcpy(outBuffer, charMatrix, iSize);
    memcpy(outBuffer + iSize, inBuffer, iLength);
    objNewStream = ASMemStmRdOpen(outBuffer, iLength + iSize);
    newContent = CosNewStream(cosDoc, true, objNewStream, 0, true, CosNewNull(), CosNewNull(), -1);
    ASStmClose(objNewStream);
    CosDictPut(cosPage, atom, newContent);
    }}

    Its working well for raster page. I dont know what is wrong with the code. Please help me in this.

    One more question, have tried with different file where i got "stream array" and i dont know how to use it for this operation. Could you please help me in this too.

    Thanks
    Rajeshrv
    Rajeshrv@adobeforums.com Guest

  6. #6

    Default Re: Shrinking of PDF Page



    have tried with different file where i got "stream array" and i dont know
    how to use it for this operation. Could you please help me in this too.




    Add 2 new array elements, one at the start and one at the end. The first one would be your "q x x x x x x cm" stream and the last one would simply be "Q".
    PDL@adobeforums.com Guest

  7. #7

    Default Re: Shrinking of PDF Page

    that's why it's actually easier to ALWAYS work with arrays, putting the prefix in one stream and the postfix in teh last one. For a simple stream, create a new array and your stream to the array.
    Leonard_Rosenthol@adobeforums.com Guest

  8. #8

    Default Re: Shrinking of PDF Page

    Leonard we know you are with Adobe but PDL would you mind telling us who you are...
    In order to consider your inputs (that always sound so knowledgeable) we'd like to know if you are or not an authorized Adobe employee or just someone that has fun providing amateur support on these forums...

    This is a User-to-User (Adobe HOSTED) forum; it's good if we know the people are giving the answers here...

    patpat
    patpat@adobeforums.com Guest

  9. #9

    Default Re: Shrinking of PDF Page

    Hi PDL,

    As you mentioned, i have added the "Q" operator at the end but the result is same. Do i need to do anything else other than the "Q" operator.

    "Also remember to match your graphics state operators"

    Could you please tell me what does it mean.

    Looking forward your help.

    Thanks
    Rajeshrv
    Rajeshrv@adobeforums.com Guest

  10. #10

    Default Re: Shrinking of PDF Page

    Without seeing an actual PDF that demonstrates the problem, we can only guess :(
    Leonard_Rosenthol@adobeforums.com Guest

  11. #11

    Default Re: Shrinking of PDF Page

    Rajeshrv,

    I think in the above line you are trying to tell about the "q and Q" operators,
    if my understanding in wrong please correct me.




    You're right on - that's exactly what I was saying.

    Your content stream (assuming you've added the ending "Q") appears to be correct. In that case, Leonard is right - can you post example PDFs somewhere (both before and after rescaling) that we can take a look at?
    PDL@adobeforums.com Guest

  12. #12

    Default Re: Shrinking of PDF Page

    Hi PDL, I sent the files to Leanard and he said that i have truncated the stream.

    From Leanard's input i have changed the length randomly and got the expected output.

    ASInt32 iLength = CosStreamLength(content); inBuffer = (char*)ASmalloc(iLength);
    ASInt32 bytesRead = ASStmRead(inBuffer, iLength, 1, objContentStream);




    but whats wrong in the code, which api should i use to get the exact length of the stream or should i do some calculation to get it.
    Rajeshrv@adobeforums.com Guest

  13. #13

    Default Re: Shrinking of PDF Page

    What is content and what is objContentStream?
    Bernd Alheit Guest

  14. #14

    Default Re: Shrinking of PDF Page

    Hi Bernd Alheit,

    Thanks for your interest.

    Please check my previous posts.
    I have already given the code.

    Rajeshrv
    Rajeshrv@adobeforums.com Guest

  15. #15

    Default Re: Shrinking of PDF Page

    Rajeshrv,

    You should consider just turning your single content stream into an array of content streams. That way you don't need to worry about truncating the existing content stream - just append your concatenation matrix as a separate stream in the array before the existing stream and append your restore graphics state stream at the end of the array.

    Basically, create a new CosArray with 3 items. Set item 1 as your "q x x x x x x cm " stream, item 3 as your "Q" stream and item 2 as the existing content stream. Then replace the current page content stream with the CosArray you created.
    PDL@adobeforums.com Guest

  16. #16

    Default Re: Shrinking of PDF Page

    Hi guys,

    I have done it with your help. Shrinking or expanding the page content is working for all the files that i have tested.

    And thank you very much for all your support.

    Thanks
    Rajeshrv.
    Rajeshrv@adobeforums.com Guest

Similar Threads

  1. The incredible shrinking icon.
    By baldoldfart@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 3
    Last Post: September 7th, 02:57 PM
  2. I'm SHRINKING!!...not quite
    By fred_martin@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 6
    Last Post: July 31st, 05:35 PM
  3. Shrinking PDFs
    By Vladimir Misev in forum Adobe Acrobat Macintosh
    Replies: 1
    Last Post: January 30th, 09:12 PM
  4. shrinking database with sqldmo
    By chris in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: July 8th, 05:28 PM
  5. Replies: 4
    Last Post: July 3rd, 10:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139