Ask a Question related to Adobe Acrobat SDK, Design and Development.
-
Rajeshrv@adobeforums.com #1
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
-
shrinking photo/dpi gets worse!
Correct me if I'm wrong, but images are supposed to look better when downsized, not worse. I'm using PS 7 on a PC....lately, when I take a photo and... -
I'm SHRINKING!!...not quite
I have a photo heavy newsletter created in Illustrator CS1 that I need to make into a small pdf file. What's the best way to shrink the file size... -
Shrinking PDFs
Frederik Paul wrote: in acrobat 6.0 menu:Advanced/PDF Optimizer, and use save as, not save. save will make file even bigger. hope this will... -
shrinking database with sqldmo
Hi, I am trying to shrink a database using sqldmo. I get the following errors with this code, in visual basic 5.0 "expected function or... -
PDL@adobeforums.com #2
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
-
Rajeshrv@adobeforums.com #3
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
-
NiceNix@adobeforums.com #4
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 document - 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
-
Rajeshrv@adobeforums.com #5
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
-
PDL@adobeforums.com #6
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
-
Leonard_Rosenthol@adobeforums.com #7
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
-
patpat@adobeforums.com #8
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
-
Rajeshrv@adobeforums.com #9
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
-
Leonard_Rosenthol@adobeforums.com #10
Re: Shrinking of PDF Page
Without seeing an actual PDF that demonstrates the problem, we can only guess :(
Leonard_Rosenthol@adobeforums.com Guest
-
PDL@adobeforums.com #11
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
-
Rajeshrv@adobeforums.com #12
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
-
Bernd Alheit #13
Re: Shrinking of PDF Page
What is content and what is objContentStream?
Bernd Alheit Guest
-
Rajeshrv@adobeforums.com #14
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
-
PDL@adobeforums.com #15
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
-
Rajeshrv@adobeforums.com #16
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



Reply With Quote

