-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete object from pdf #485
Comments
removing an object from a file is not really an option with PDF Modifications. You may mark it as deleted with I'm fairly sure Depending on how exactly you are copying the file you can avoid copying it in the first place or replace (via ReplaceSourceObjects) it with an object that's content is null (just create a new object, make its content a null pdf keyword and finish it, now you got a null object). |
Oh, really hard. How can I copy objects step by step while replacing old ones? I'm trying to do it something like this: inPDFWriter.StartPDF("/home/ivan/pdf/test_2_image_modyfy.pdf", ePDFVersion14); copyingContext->CopyNewObjectsForDirectObject(objectIDTypeList); // let's imagine that I created objectIDTypeList In general, my task is to copy a PDF file with the substitution of some objects (pictures), how can I do this? Sorry to waste your time, I'm just a little short on documentation... |
Its alright, sorry for the doc being short. ok, so for general copying of a pdf but replacing some of its object you would want a combination of copying the full pdf + using copyingContext.ReplaceSourceObjects for those objects you want to replace. To copy the full PDF you can use code similar to the one in the library RecryptPDF function, which basically does just that - it copies the full pdf by recursively copying from the root object, using copyingContext->CopyObject (which is recursive), then sets the root of the new PDF to be the copied object. you can find the code here: Now, prior to calling CopyObject you'll want to create the replacement images in the target PDF. Alternatively allocate object IDs from them to be used after copying, if you prefer to do them afterwards.
The map keys are the original images IDs (those in the source document). and the values are the target image ids. So the code should largely look something like this:
Note - depending on your overall intent you might want to replace only part of the document, like specific pages. in this case, dont query the original root and set the result root on the target document. rather query the original object (say page) and create a relevant target object (say a page). we can get into this difference if it matters to you. |
Yes it works as I wanted, thank you very much! |
First on yr second question: if you need to copy the whole PDF don't mind my note :). As for images, CreateImageXObjectFromJPGFile and CreateImageXObjectFromJPGFile are good choices, where the latter will create a form xobject with the native size of the image, instead of 1X1 image object that you should scale (well..maybe you'll need to scale the form as well). CreateFormXObjectFromWHATEVERFile gets a file path (or stream) and then embeds the image in the file. CreateFormXObjectFromWhateverFile returns a PDFFormXObject pointer which you can use to acquire its id with you should also delete that formXObject object once you are done with it. b.t.w if using CreateImageXObjectFromJPGFile instead you will get back a PDFImageXObject which you can use its GetImageObjectID to get its uid. you'll probably want to create a from to size it up and then use that form ID in your list. there's examples on how to use these function in the test files of PDFWriter. depending on what exactly you end up doing i can provide further help, but lets see first how do you want to approach this. |
I think I managed to figure it out. Now my program works as I wanted. Thank you very much for your help and for the library) |
Hello!
I'm trying to delete an object in a copied PDF file, the object is deleted visually, but still remains in memory. How to completely remove an object from a file?
I use:
inPDFWriter.GetObjectsContext().StartModifiedIndirectObject(xobjectID);
objectsRegistry.DeleteObject(xobjectID);
The text was updated successfully, but these errors were encountered: