|
I am working with QuickPDF Library 11.15 using the ActiveX C# interface on a PDF that has both visible and non-visible Optional Content Groups (OCGs) and my goal is: 1. Determine the OCGs present and which ones are visible and non-visible 2. Remove the non-visible OCGs and their content from the document 3. Save the PDF which now has just the visible OCGs remaining
Based on the Library documentation, this seemed simple enough, but I am running into various problems. The source PDF I am testing with has one page and two OCGS - a visible OCG containing English text and a non-visible OCG containing French text. Based on the code snippet below, I expect that QuickPDF will tell me that the first OCG is visible and the second one non-visible:
string sourceDoc = @"..\..\Test Files\samplepdfwithlayers.pdf"; qp.LoadFromFile(sourceDoc, "");
// Count OCGs int OCGCount = qp.OptionalContentGroupCount(); // Loop through each OCG and delete it for (int i = 1; i <= OCGCount; i++) { int OCGID = qp.GetOptionalContentGroupID(i); int visible = qp.GetOptionalContentGroupVisible(OCGID); }
Okay, so far, so good, QuickPDF does indeed indicate on visible and one non-visible OCG.
Next, I want to add a call to Remove the non-visible OCG and then save what should now be a PDF with just the single remaining visible, English text, OCG:
string sourceDoc = @"..\..\Test Files\samplepdfwithlayers.pdf"; string destfileName = @"..\..\Test Files\convertedPDFA.pdf"; qp.LoadFromFile(sourceDoc, "");
// Count OCGs int OCGCount = qp.OptionalContentGroupCount(); //should be 2 initially // Loop through each OCG and delete any that are non-visible for (int i = 1; i <= OCGCount; i++) { int OCGID = qp.GetOptionalContentGroupID(i); int visible = qp.GetOptionalContentGroupVisible(OCGID); if (visible == 0) //if invisible, delete the OCG { qp.DeleteOptionalContentGroup(OCGID); } }
// Count OCGs again OCGCount = qp.OptionalContentGroupCount(); //should be 1 now
qp.SaveToFile(destfileName);
So, here is the problem - the new PDF does have just one remaining OCG but instead of only showing the English text from the original visible OCG, it shows both the English AND French text on top of each other!
Can someone tell me why the French text is even still in the PDF and why it has been put into the remaining OCG? How do I make sure that content from a removed OCG is removed from the PDF?
Thanks!
|