Reputation: 113
I have a pdf document with many layers (OCGs). This doc has only one page. There are few bitmap images and many vector graphics in this doc. Each of vector graphics is related to one of layer (OCG).
I need to extract vector graphics from the document. I tried to use some tools as GSview and Inkscape and got one huge svg document. Unfortunately, I need to extract separate graphics for each of layers (OCGs).
I tried to use libraries ABCpdf, Aspose and iTextSharp, but didn't get what I need. Yes, I can add vector graphics to pdf using iTextSharp, but I need to extract it. Probably, one of these libraries could offer suitable solution but I didn't find it during several hours of researching.
Now I'm digging in Acrobat SDK, but I'm very new to this, and my experience with C/C++ is very poor.(
Upvotes: 2
Views: 3144
Reputation: 1222
ABCpdf, to which you refer, contains an Example project called OCGLayers. This project shows you how to identify and redact all the items in a layer.
The easiest thing to do here will be to redact all the layers that you don't want and then save the document. This is because layers that are not visible can still affect the placement or style of a visible layer.
By redacting the invisible layers you leave behind the positioning and styles that are required by your visible layer while at the same time removing the content from any unwanted layers.
Upvotes: 0
Reputation: 1828
If you are still looking for a solution, the XFINIUM.PDF library supports this feature.
The code below shows how this feature works (extracts optional content from one page and draws it on another):
FileStream input = File.OpenRead("optionalcontent-src.pdf");
PdfFile file = new PdfFile(input);
int pageNumber = 0;
string ocgName = "SampleOCG";
PdfPageOptionalContent ocg = file.ExtractPageOptionalContentGroup(pageNumber, ocgName);
input.Close()
PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();
page.Graphics.DrawFormXObject(ocg, 0, 0, page.Width / 2, page.Height / 2);
document.Save("optionalcontent-dest.pdf")
The optional content is extracted by name.
Disclaimer: I work for the company that develops this product.
Upvotes: 1