asp.net open pdf in new window code behind : Compress pdf SDK software API .net winforms windows sharepoint itext_so-sample6-part668

Interactiveforms
55
Howtofilloutapdffileprogrammatically?(Dynamic
XFA)
IhaveadynamicXFAFormthatIcanfilloutmanuallyusingAdobeAcrobatonmy
computer.UsingiTextSharpIcanreadwhattheXFAXMLdataisandseethestructureof
thedata.IamessentiallytryingtomimicthatwithiTextusingthefollowingcode:
PdfReader pdfReader r = new PdfReader(sourceFilePath);
using (MemoryStream ms = new MemoryStream()) {
using (PdfStamper stamper = new PdfStamper(pdfReader, ms)) ) {
XfaForm xfaForm = new XfaForm(pdfReader);
XmlDocument doc = new XmlDocument();
doc.Load(replacementXmlFilePath);
xfaForm.DomDocument = = doc;
xfaForm.Changed = true;
XfaForm.SetXfa(xfaForm, stamper.Reader, stamper.Writer);
}
var bytes = = ms.ToArray();
File.WriteAllBytes(destinationtFilePath, bytes);
}
Forsomereasonthiscodedoesn’twork.
PostedonStackOverflowonMay11,2013⁹⁸byjon333⁹⁹
Thisquestionwasansweredbythepersonwhopostedthequestion:
Ifoundtheissue.ThereplacementDomDocumentneedstobetheentiremergedXMLof
thenewdocument,notjustthedataordatasetsportion.
Iupvotedthisanswer,becauseit’snotincorrect,butnowthatIthinkit’sbettertousetheexample
fromthebook¹⁰⁰:
⁹⁸
http://stackoverflow.com/questions/16502427/how-can-i-set-xfa-data-in-a-static-xfa-form-in-itextsharp-and-get-it-to-save
⁹⁹
http://stackoverflow.com/users/511518/jon333
¹⁰⁰
http://itextpdf.com/examples/iia.php?id=165
Compress pdf - Compress reduce PDF size in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
C# Code & .NET API to Compress & Decompress PDF Document
adjust pdf page size; change paper size in pdf
Compress pdf - VB.NET PDF File Compress Library: Compress reduce PDF size in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
VB.NET PDF Document Compression and Decompression Control SDK
batch pdf compression; best pdf compressor
Interactiveforms
56
public byte[] ManipulatePdf(String src, String xml) {
PdfReader reader = new PdfReader(src);
using (MemoryStream ms = new MemoryStream()) {
using (PdfStamper stamper = new PdfStamper(reader, ms)) {
AcroFields form = stamper.AcroFields;
XfaForm xfa = form.Xfa;
xfa.FillXfaForm(XmlReader.Create(new StringReader(xml)));
}
return ms.ToArray();
}
}
Asyoucansee,it’snotnecessarytoreplacethewholeXFAXML.Ifyouusethe
FillXfaForm
method,
thedataissufficient.
C# WPF PDF Viewer SDK to view, annotate, convert and print PDF in
Split PDF Document. File: Compress PDF. Page: Create Thumbnails. Page: Insert PDF Pages. Page: Delete Existing PDF Pages. Page: Replace
pdf text box font size; change page size pdf
VB.NET Create PDF from PowerPoint Library to convert pptx, ppt to
Split PDF Document. File: Compress PDF. Page: Create Thumbnails. Page: Insert PDF Pages. Page: Delete Existing PDF Pages. Page: Replace
pdf compressor; pdf optimized format
Interactiveforms
57
HowtofillXFAformusingiTextwithoutbreaking
usagerights?
Thisismycode:
using (FileStream pdf = new FileStream("C:/test.pdf", FileMode.Open))
using (FileStream xml = new FileStream("C:/test.xml", FileMode.Open))
using (FileStream filledPdf f = new FileStream("C:/test_f.pdf", FileMode.Create))
{
PdfReader pdfReader r = new PdfReader(pdf);
PdfStamper stamper = new PdfStamper(pdfReader, , filledPdf);
stamper.AcroFields.Xfa.FillXfaForm(xml);
stamper.Close();
pdfReader.Close();
}
ThiscodethrowsnoexceptionandeverythingseemstobeOK,butifIopenfilledpdf,
AdobeReadersayssomethinglikethis:
Thisdocumentenabledextendedfeatures.Thisdocumentwaschangedsince
itwascreatedandusingextendedfeaturesisn’tpossibleanymore.
IfIchoosexmlmanuallybyclicking‘Importdata’fromAdobeReader,formisfilled
properly,soIguessthereisnoerrorinxml.
PostedonStackOverflowonOct29,2014¹⁰¹bypaldir¹⁰²
Youarenotcreatingthe
PdfStamper
objectcorrectly.Use:
PdfStamper stamper r = new PdfStamper(pdfReader, , filledPdf, '\0'true)
Inyourcode,youarenotusing
PdfStamper
inappendmode.ThismeansthatiTextwillreorganize
thedifferentobjectsinyourPDF.Usuallythatisn’taproblem.
However:yourPDFisReader-enabled,whichmeansthatyourPDFisdigitallysignedusingaprivate
keyownedbyAdobe.ByreorganizingtheobjectsinsidethePDF,thatsignatureisbroken.Thisis
madeclearbythemessageyoualreadymentioned:
Thisdocumentenabledextendedfeatures.Thisdocumentwaschangedsinceitwas
createdandusingextendedfeaturesisn’tpossibleanymore.
¹⁰¹
http://stackoverflow.com/questions/26629498/how-to-fill-xfa-form-using-itext
¹⁰²
http://stackoverflow.com/users/4148435/paldir
VB.NET Create PDF from Word Library to convert docx, doc to PDF in
Split PDF Document. File: Compress PDF. Page: Create Thumbnails. Page: Insert PDF Pages. Page: Delete Existing PDF Pages. Page: Replace
best online pdf compressor; change font size in pdf form field
VB.NET PDF- HTML5 PDF Viewer for VB.NET Project
Split PDF Document. File: Compress PDF. Page: Create Thumbnails. Page: Insert PDF Pages. Page: Delete Existing PDF Pages. Page: Replace
change font size pdf document; can a pdf be compressed
Interactiveforms
58
Toavoidbreakingthesignature,youneedtouse
PdfStamper
inappendmode.Insteadofreorganiz-
ingtheoriginalcontent,iTextwillnowkeeptheoriginalfileintactandappendnewcontentafter
theendoftheoriginalfile.
C# HTML5 PDF Viewer SDK to view PDF document online in C#.NET
Split PDF Document. File: Compress PDF. Page: Create Thumbnails. Page: Insert PDF Pages. Page: Delete Existing PDF Pages. Page: Replace
change font size pdf text box; adjust pdf size
C# PDF Image Extract Library: Select, copy, paste PDF images in C#
PDF ›› C# PDF: Extract PDF Image. How to C#: Extract Image from PDF Document. Support PDF Image Extraction from a Page, a Region on a Page, and PDF Document.
change font size pdf fillable form; best pdf compression
Actionsandannotations
Allthingsinteractivearediscussedhere.Exceptforforms,we’vealreadycoveredthese.
Howtocreatealinktoaspecificpagenumber?
IknowhowtotargetanytextofanyPDFpageusingcode:
Anchor click k = new Anchor("Click to o go to o Target");
click.Reference = "#target";
Paragraph p1 = new Paragraph();
p1.Add(click);
doc.Add(p1);
Anchor target t = new Anchor("Target");
target.Name = "target";
doc.Add(target);
Myquestionishowtotargetapagebasedonitsnumber.Forexampleiftargetedpage
numberis6,clickingontheAnchortextshouldtaketo6thpage.
PostedonStackOverflowonFeb20,2014¹⁰³byYogesh¹⁰⁴
Insteadofan
Anchor
,youneeda
Chunk
.Tothis
Chunk
youneedtoadda
PdfAction
.Theaction
needstobeagotoLocalPage()¹⁰⁵action.
Forinstance:
Chunk chunk k = New Chunk("Go to page 5");
PdfAction action = PdfAction.GotoLocalPage(5, New PdfDestination(0), , writer);
chunk.SetAction(action);
¹⁰³
http://stackoverflow.com/questions/21907184/itextsharp-how-to-target-pdf-page-number
¹⁰⁴
http://stackoverflow.com/users/532384/yogesh
¹⁰⁵
http://api.itextpdf.com/itext/com/itextpdf/text/pdf/PdfAction.html#gotoLocalPage%28int,%20com.itextpdf.text.pdf.PdfDestination,%20com.
itextpdf.text.pdf.PdfWriter%29
VB.NET PDF Text Extract Library: extract text content from PDF
PDF ›› VB.NET PDF: Extract PDF Text. VB.NET PDF - Extract Text from PDF Using VB. How to Extract Text from PDF with VB.NET Sample Codes in .NET Application.
pdf files optimized; can pdf files be compressed
VB.NET PDF Library SDK to view, edit, convert, process PDF file
Generally speaking, you can use this .NET document imaging SDK to load, create, edit, convert, protect, compress, extract, and navigate PDF document (page).
change font size in pdf form; pdf compression settings
Actionsandannotations
60
Howtoinserta“linkedrectangle”withiText?
IwanttoinsertahyperlinkintoanexistingPDFatapositionIknowinadvance:Ialready
havethecoordinatesofarectangleonagivenpage.Iwanttolinkthisrectangletoanother
pageofthesamePDF(whichIalsoknowinadvance).HowdoIachievethis?
PostedonStackOverflowonNov7,2013¹⁰⁶byHansStricker¹⁰⁷
PleasetakealookattheAddLinkAnnotation¹⁰⁸example.
Asyou(should)alreadyknow(butyoudidn’tshowwhatyou’vealreadytried,whichiskindof
mandatoryonStackOverflow),youcanuse
PdfStamper
tomanipulateanexistingPDF.Addinga
rectangularlinkononepagetoanotherpage,isassimpleasaddingalinkannotationtothatpage:
PdfReader reader new PdfReader(src);
PdfStamper stamper new PdfStamper(readernew FileOutputStream(dest));
Rectangle linkLocation new Rectangle(523, 770, 559, 806);
PdfDestination destination new PdfDestination(PdfDestination.FIT);
PdfAnnotation link PdfAnnotation.createLink(stamper.getWriter(),
linkLocationPdfAnnotation.HIGHLIGHT_INVERT,
3, destination);
link.setBorder(new PdfBorderArray(0, 0, 0));
stamper.addAnnotation(link, 1);
stamper.close();
The
link
objectiscreatedusing:
• the
writer
instancetiedtothe
stamper
,
• therectangle(thepositionyousayyouknowinadvance,
• ahighlightingoption(pickone:
HIGHLIGHT_NONE
,
HIGHLIGHT_INVERT
,
HIGHLIGHT_OUTLINE
,
HIGHLIGHT_PUSH
,
HIGHLIGHT_TOGGLE
),
• thepageyouwanttolinkto,
• adestination.
Once you have an n instance of
PdfAnnotation
, you can add d it to o a a specific c page using g the
addAnnotation()
method.
¹⁰⁶
http://stackoverflow.com/questions/22194844/inserting-a-linked-rectangle-with-itext
¹⁰⁷
http://stackoverflow.com/users/363429/hans-stricker
¹⁰⁸
http://itextpdf.com/sandbox/annotations/AddLinkAnnotation
Actionsandannotations
61
HowtoaddamapswithapointertoaPDF?
IamusingjavaandiTexttocreateapdf.Isitpossibletoaddamapwithapointeronitso
theuserwillknowwherethestartingpointis?
PostedonStackOverflowonNov6,2014¹⁰⁹byuser2487493¹¹⁰
Whatdoyoumeanby“amapwithapointersotheuserknowswherethestartingpointis”?Ifyou
haveamapinyourPDF,youcouldaddanannotationthatlookslikeanarrow.Isthatwhatyou’re
lookingfor?
Sinceyoudidn’tanswermycounter-questionaddedincomment,I’mprovidingtwoexamples.If
thesearenotwhatyou’relookingfor,youreallyshouldclarifyyourquestion.
Example1:addacustomshapeasextracontentontopofamap
ThisisdemonstratedintheAddPointer¹¹¹example:
PdfContentByte canvas writer.getDirectContent();
canvas.setColorStroke(BaseColor.RED);
canvas.setLineWidth(3);
canvas.moveTo(220, 330);
canvas.lineTo(240, 370);
canvas.arc(200, 350, 240, 390, , 0, , (float) 180);
canvas.lineTo(220, 330);
canvas.closePathStroke();
canvas.setColorFill(BaseColor.RED);
canvas.circle(220, 370, 10);
canvas.fill();
Ifweknowthecoordinatesofthepointer,wecandrawlinesandcurvesthatresultinathered
pointershownhere(seetheredpinneartheCambridgeInnovationCenter):
¹⁰⁹
http://stackoverflow.com/questions/26752663/adding-maps-at-itext-java
¹¹⁰
http://stackoverflow.com/users/2487493/user2487493
¹¹¹
http://itextpdf.com/sandbox/objects/AddPointer
Actionsandannotations
62
Mapwithapin
Example2:addalineannotationontopofamap
ThisisdemonstratedintheAddPointerAnnotation¹¹²example:
Rectangle rect new Rectangle(220, 350, 475, 595);
PdfAnnotation annotation PdfAnnotation.createLine(writerrect,
"Cambridge Innovation n Center", 225, 355, 470, 590);
PdfArray le new PdfArray();
le.add(new PdfName("OpenArrow"));
le.add(new PdfName("None"));
annotation.setTitle("You are here:");
annotation.setColor(BaseColor.RED);
annotation.setFlags(PdfAnnotation.FLAGS_PRINT);
annotation.setBorderStyle(
new PdfBorderDictionary(5, PdfBorderDictionary.STYLE_SOLID));
annotation.put(new PdfName("LE"), le);
annotation.put(new PdfName("IT"), new PdfName("LineArrow"));
writer.addAnnotation(annotation);
Theresultisanannotation(whichisn’tpartoftherealcontent,butpartofaninteractivelayeron
topoftherealcontent):
¹¹²
http://itextpdf.com/sandbox/annotations/AddPointerAnnotation
Actionsandannotations
63
Mapwithanannotation
Itisinteractiveinthesensethatextrainfoisshownwhentheuserclickstheannotation:
Mapwithanannotationthathasbeenopened
Manyotheroptionsarepossible,butonceagain:yourquestionwasn’tentirelyclear.
ExtractingtextfromPDFs
iTextcanparsePDFstoextractthecontentofapage.Astherearemanydifferentwaystocreatea
PDFfile,andasthetextonapageusuallyisn’tmorethanabunchofcharactersdrawnonapage,
it’snottrivialtoextracttextcorrectly.
Howtoreadtextfromaspecificposition?
IhaveaproblemusingiTextSharpwhenreadingdatafromPDFFile.WhatIwanttoachieve
istoreadonlyspecificpartofPDFpage(IwanttoonlyretrieveAddressInformation,which
islocatedatconstantposition).IhaveseenusingiTextSharpforreadingallpagessuchas
following:
StringBuilder text t = new StringBuilder();
if (File.Exists(fileName)) {
PdfReader pdfReader r = new PdfReader(fileName);
for (int page = 1; page <= pdfReader.NumberOfPages; page++) {
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentText = = PdfTextExtractor.GetTextFromPage(pdfReader, page, , \
strategy);
currentText = = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.De\
fault, Encoding.UTF8, , Encoding.Default.GetBytes(currentText)));
text.Append(currentText);
}
pdfReader.Close();
}
return text.ToString();
ButhowcanIonlyrestrictittoaspecificlocation?
PostedonStackOverflowonJun12,2014¹¹³byRobertJ.¹¹⁴
Youareusinga
SimpleTextExtractionStrategy
insteadofa
LocationTextExtractionStrategy
.If
rect
isarectanglebasedonthecoordinatesofyouraddress,youneed:
¹¹³
http://stackoverflow.com/questions/24185066/itextsharp-read-from-specific-position
¹¹⁴
http://stackoverflow.com/users/1539189/robert-j
Documents you may be interested
Documents you may be interested