How to add u3d into existing pdf using itext7 with C#
Tag : chash , By : Lathentar
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The Linked example is for iText5, not iText7. In iText7 this example would look like this public static final String DEST = "./target/test/resources/book/part4/chapter16/Listing_16_16_Pdf3D.pdf";
public static String RESOURCE = "./src/test/resources/img/teapot.u3d";
public static void main(String args[]) throws Exception {
new Listing_16_16_Pdf3D().manipulatePdf(DEST);
}
public void manipulatePdf(String dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc);
Rectangle rect = new Rectangle(100, 400, 400, 400);
PdfStream stream3D = new PdfStream(pdfDoc, new FileInputStream(RESOURCE));
stream3D.put(PdfName.Type, new PdfName("3D"));
stream3D.put(PdfName.Subtype, new PdfName("U3D"));
stream3D.setCompressionLevel(CompressionConstants.DEFAULT_COMPRESSION);
stream3D.flush();
PdfDictionary dict3D = new PdfDictionary();
dict3D.put(PdfName.Type, new PdfName("3DView"));
dict3D.put(new PdfName("XN"), new PdfString("Default"));
dict3D.put(new PdfName("IN"), new PdfString("Unnamed"));
dict3D.put(new PdfName("MS"), PdfName.M);
dict3D.put(new PdfName("C2W"),
new PdfArray(new float[]{1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28}));
dict3D.put(PdfName.CO, new PdfNumber(235));
Pdf3DAnnotation annot = new Pdf3DAnnotation(rect, stream3D);
annot.setContents(new PdfString("3D Model"));
annot.setDefaultInitialView(dict3D);
pdfDoc.addNewPage().addAnnotation(annot);
doc.close();
}
public void manipulatePdf(String dest) {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc);
Rectangle rect = new Rectangle(100, 400, 400, 400);
PdfStream stream3D = new PdfStream(pdfDoc, new FileInputStream(RESOURCE));
stream3D.Put(PdfName.Type, new PdfName("3D"));
stream3D.Put(PdfName.Subtype, new PdfName("U3D"));
stream3D.SetCompressionLevel(CompressionConstants.DEFAULT_COMPRESSION);
stream3D.Flush();
PdfDictionary dict3D = new PdfDictionary();
dict3D.Put(PdfName.Type, new PdfName("3DView"));
dict3D.Put(new PdfName("XN"), new PdfString("Default"));
dict3D.Put(new PdfName("IN"), new PdfString("Unnamed"));
dict3D.Put(new PdfName("MS"), PdfName.M);
dict3D.Put(new PdfName("C2W"),
new PdfArray(new float[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28 }));
dict3D.Put(PdfName.CO, new PdfNumber(235));
Pdf3DAnnotation annot = new Pdf3DAnnotation(rect, stream3D);
annot.SetContents(new PdfString("3D Model"));
annot.SetDefaultInitialView(dict3D);
pdfDoc.AddNewPage().AddAnnotation(annot);
doc.Close();
}
|
itext7 - adding content from existing PDF to a new one
Tag : java , By : HokieGeek
Date : March 29 2020, 07:55 AM
To fix the issue you can do To stamp your template page origPage onto the current first page of pdf instead of a new one, simply replace PdfPage page = pdf.addNewPage(1, PageSize.A4);
PdfPage page = pdf.getPage(1);
|
Get all metadata from an existing PDF using iText7
Tag : chash , By : user147496
Date : March 29 2020, 07:55 AM
This might help you In iText 7 the PdfDocumentInfo class unfortunately does not expose a method to retrieve the keys in the underlying dictionary. But you can simply retrieve the Info dictionary contents by immediately accessing that dictionary from the trailer dictionary. E.g. for a PdfDocument pdfDocument: PdfDictionary infoDictionary = pdfDocument.GetTrailer().GetAsDictionary(PdfName.Info);
foreach (PdfName key in infoDictionary.KeySet())
Console.WriteLine($"{key}: {infoDictionary.GetAsString(key)}");
|
How to write text under underline in itext7
Tag : pdf , By : hlpimfalling
Date : March 29 2020, 07:55 AM
wish of those help This is fairly easy to implement using text rise setting which is a standard setting in PDF. Below is a brief code sample: Paragraph p = new Paragraph();
p.add("The beginning of the line ");
p.add(new Text(" (fill in your name) ").setTextRise(-10).setUnderline().setFontSize(8));
p.add(" end of the line");
|
Add an image to an existing PDF file with iText7
Tag : chash , By : Tetting
Date : March 29 2020, 07:55 AM
wish helps you In iText7, there is no PdfStamper anymore. PdfDocument is responsible for modifying the contents of the document. To add an image to a page, the easiest way is to use Document class from layout module. With that you almost don't have to care about anything. // Modify PDF located at "source" and save to "target"
PdfDocument pdfDocument = new PdfDocument(new PdfReader(source), new PdfWriter(target));
// Document to add layout elements: paragraphs, images etc
Document document = new Document(pdfDocument);
// Load image from disk
ImageData imageData = ImageDataFactory.Create(imageSource);
// Create layout image object and provide parameters. Page number = 1
Image image = new Image(imageData).ScaleAbsolute(100, 200).SetFixedPosition(1, 25, 25);
// This adds the image to the page
document.Add(image);
// Don't forget to close the document.
// When you use Document, you should close it rather than PdfDocument instance
document.Close();
|