Mix and match
bearbeiten & zusammenstellen von PDF Dokumenten
Die 3-Heights™ PDF Toolbox ist eine hochperformante, plattformunabhängige Komponente für das Erzeugen und Assemblieren von PDF/A konformen Dokumenten.
Dokumentenzusammenstellung
Inhaltsgenerierung
Farben
Pfade
Text
Bilder
Transformationen
Änderung von Inhalt
Extrahieren
Unterstützte PDF-Formate
Unterstützte Bildformate
Unterstützte Schriftformate
Grosse Informationsmengen werden auf Datenbank- und DMS-Systemen gespeichert. Die PDF Toolbox eignet sich, um diese Informationen entgegen zu nehmen und daraus verteilbare und standardisierte PDF Dokumente zu erstellen. Somit wird auch die Distribution über Infrastrukturen mit verschiedensten Technologien und Betriebssystemen ermöglicht.
Füge jeder Seite eines PDF Dokuments einen transparenten Stempeltext hinzu. Optional können die Farbe und die Deckkraft des Stempels festgelegt werden.
// Open input document
using (Stream inStream = new FileStream(inPath, FileMode.Open, FileAccess.Read))
using (Document inDoc = Document.Open(inStream, null))
// Create output document
using (Stream outStream = new FileStream(outPath, FileMode.Create, FileAccess.ReadWrite))
using (Document outDoc = Document.Create(outStream, Conformance.Unknown, null))
using (Font font = outDoc.CreateSystemFont("Arial", "Italic", true))
{
// Set output intent
if (inDoc.OutputIntent != null)
using (ColorSpace outputIntent = outDoc.CopyColorSpace(inDoc.OutputIntent))
outDoc.OutputIntent = outputIntent;
// Copy metadata
using (Metadata metadata = outDoc.CopyMetadata(inDoc.Metadata))
outDoc.Metadata = metadata;
// Set copy options
CopyOption copyOptions = CopyOption.CopyLinks | CopyOption.CopyAnnotations |
CopyOption.CopyFormFields | CopyOption.CopyOutlines | CopyOption.CopyLogicalStructure;
// Get the device color space
using (ColorSpace colorspace = outDoc.CreateDeviceColorSpace(DeviceColorSpaceType.RGB))
// Create paint object with the choosen RGB color
using (paint = outDoc.CreateAlphaPaint(colorspace, alpha, 1.0, 0.0, 0.0))
{
// Loop through all pages of input
foreach (Page inPage in inDoc.Pages)
{
// Copy page from input to output
using (Page outPage = outDoc.CopyPage(inPage, copyOptions))
{
// Add text to page
AddStamp(outDoc, outPage, stampString, font, 50);
// Add page to document
outDoc.Pages.Add(outPage);
}
}
}
}
private static void AddStamp(Document outputDoc, Page outPage, string stampString,
Font font, double fontSize)
{
// Create content generator and text object
using (ContentGenerator gen = new ContentGenerator(outPage.Content, false))
using (Text text = outputDoc.CreateText())
{
// Create text generator
using (TextGenerator textgenerator = new TextGenerator(text, font, fontSize, null))
{
// Calculate point and angle of rotation
Point rotationCenter = new Point
{
X = outPage.Size.Width / 2.0,
Y = outPage.Size.Height / 2.0
};
double rotationAngle = Math.Atan2(outPage.Size.Height,
outPage.Size.Width) / Math.PI * 180.0;
// Rotate textinput around the calculated position
Transformation trans = new Transformation();
trans.RotateAround(rotationAngle, rotationCenter);
gen.Transform(trans);
// Calculate position
Point position = new Point
{
X = (outPage.Size.Width - textgenerator.GetWidth(stampString)) / 2.0,
Y = (outPage.Size.Height - font.Ascent * fontSize) / 2.0
};
// Move to position
textgenerator.MoveTo(position);
// Set text rendering
textgenerator.SetRendering(paint, null, false);
// Add given stamp string
textgenerator.ShowLine(stampString);
}
// Paint the positioned text
gen.PaintText(text);
}
}
// Open input document
inStream = new FileStream(inPath, "r");
inDoc = Document.open(inStream, null);
// Create output document
outStream = new FileStream(outPath, "rw");
outStream.setLength(0);
outDoc = Document.create(outStream, Conformance.UNKNOWN, null);
// Create embedded font in output document
Font font = outDoc.createSystemFont("Arial", "Italic", true);
// Set output intent
if (inDoc.getOutputIntent() != null)
outDoc.setOutputIntent(outDoc.copyColorSpace(inDoc.getOutputIntent()));
// Copy metadata
Metadata metadata = outDoc.copyMetadata(inDoc.getMetadata());
outDoc.setMetadata(metadata);
// Set copy options
EnumSet<CopyOption> copyOptions = EnumSet.of(CopyOption.COPY_LINKS, CopyOption.COPY_ANNOTATIONS,
CopyOption.COPY_FORM_FIELDS, CopyOption.COPY_OUTLINES, CopyOption.COPY_LOGIGAL_STRUCTURE);
// Get the device color space
ColorSpace colorSpace = outDoc.createDeviceColorSpace(DeviceColorSpaceType.RGB);
// Choose the RGB color value
double[] color = {1.0, 0.0, 0.0};
// Create paint object
paint = outDoc.createAlphaPaint(colorSpace, alpha, color);
// Loop throw all pages of input
for (Page inPage : inDoc.getPages())
{
// Copy page from input to output
Page outPage = outDoc.copyPage(inPage, copyOptions);
// Add text to page
addStamp(outDoc, outPage, stampString, font, 50);
// Add page to document
outDoc.getPages().add(outPage);
//Cleanup
outPage.close();
inPage.close();
}
private static void addStamp(Document outputDoc, Page outPage, String stampString,
Font font, double fontSize) throws ErrorCodeException
{
ContentGenerator generator = null;
try
{
// Create content generator
generator = new ContentGenerator(outPage.getContent(), false);
// Create text object
Text text = outputDoc.createText();
// Create text generator
TextGenerator textgenerator = new TextGenerator(text, font, fontSize, null);
// Calculate point and angle of rotation
Point rotationCenter = new Point(
outPage.getSize().width / 2.0,
outPage.getSize().height / 2.0
);
// Calculate rotation angle
double rotationAngle = Math.atan2(outPage.getSize().height,
outPage.getSize().width) / Math.PI * 180.0;
// Rotate text input around the calculated position
Transformation trans = new Transformation();
trans.rotateAround(rotationAngle, rotationCenter);
generator.transform(trans);
// Calculate position
Point position = new Point(
(outPage.getSize().width - textgenerator.getWidth(stampString)) / 2.0,
(outPage.getSize().height - font.getAscent() * fontSize) / 2.0
);
// Move to position
textgenerator.moveTo(position);
// Set text rendering
textgenerator.setRendering(paint, null, false);
// Add given stamp string
textgenerator.showLine(stampString);
textgenerator.close();
// Paint the positioned text
generator.paintText(text);
}
finally
{
// Close content generator
if (generator != null)
generator.close();
}
}
Assembling PDF documents from various sources is a crucial part of an output management system. And, as the document needs to be archived in most cases, it should conform to the PDF/A standard. Is there a way to assemble a document and accomplish PDF/A conformance in one step?
PDF is more and more finding its way into mass printing applications. However, PDF spool files often ask too much from a print engine resulting in aborts or, even worse, incomplete prints which may not be noticed. What is special about PDF mass printing...