pdf conversion in c# : Extract data out of pdf file application SDK utility azure .net html visual studio itext_so-sample3-part1254

Tables
25
You’remixingtextmodeandcompositemode.
Intextmode,youcreatethe
PdfPCell
witha
Phrase
astheparameteroftheconstructor,andyou
definethealignmentatthe levelofthecell. However,you’reworking incomposite mode. This
modeistriggeredassoonasyouusethe
addElement()
method.Incompositemode,thealignment
definedatthelevelofthecellisignored(whichexplainsyourproblem).Instead,thealignmentof
theseparateelementsisused.
Howtosolveyourproblem?
Eitherworkintextmodebyaddingyour
Phrase
tothecellinadifferentway.Orworkincomposite
modeandusea
Paragraph
forwhichyoudefinethealignment.
Theadvantageof composite modeover text mode isthatdifferentparagraphsin thesamecell
canhavedifferentalignments, whereasyoucanonlyhaveonealignmentintextmode.Another
advantage is that you can add more than justtext: you can also add images, lists, tables,… An
advantageof textmodeisspeed:ittakeslessprocessingtimetodealwiththecontentofacell.
How to use multiple fonts in a single cell?
I’mmakingawindowsformforafriendthatdeliverspackages.SoIwanttotransferhis
currentpaperform,intoa.pdfwiththelibraryiTextSharp.
WhatIneed:
Iwantthetabletohavealittleheadline,“Companyname”forexample,thetextshouldbe
alittlesmallerthanthetextinputfromthewindowsform.CurrentlyI’musingcellsand
waswonderingifIcanuse2differentfontsizeswithinthesamecell?
WhatIhave:
table.AddCell("Static headline" + Chunk.NEWLINE + richTextBox1.Text);
WhatI“want”:
var normalFont = = FontFactory.GetFont(FontFactory.HELVETICA, 9);
var boldFont = = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12);
table.AddCell("Static headline", boldFont + Chunk.NEWLINE + richTextBox1.Text, n\
ormalFont);
PostedonStackOverflowonFeb13,2014⁴³byFrederikKiel⁴⁴
⁴³
http://stackoverflow.com/questions/21750597/c-sharp-itextsharp-multi-fonts-in-a-single-cell
⁴⁴
http://stackoverflow.com/users/3300515/frederik-kiel
Extract data out of pdf file - extract form data from PDF in C#.net, ASP.NET, MVC, Ajax, WPF
Help to Read and Extract Field Data from PDF with a Convenient C# Solution
extract data from pdf form fields; export excel to pdf form
Extract data out of pdf file - VB.NET PDF Form Data Read library: extract form data from PDF in vb.net, ASP.NET, MVC, Ajax, WPF
Convenient VB.NET Solution to Read and Extract Field Data from PDF
how to make pdf editable form reader; extracting data from pdf forms to excel
Tables
26
You’repassinga
String
anda
Font
to the
AddCell()
method.That’snotgoingtowork.Youneed
the
AddCell()
methodthattakesa
Phrase
objectora
PdfPCell
objectasparameter.
A
Phrase
isanobjectthatconsistsofdifferent
Chunk
s,andthedifferent
Chunk
scanhavedifferent
fontsizes.Forinstance:
Phrase phrase = new Phrase();
phrase.Add(
new Chunk("Some BOLD text", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.\
BOLD))
);
phrase.Add(new Chunk(", some normal text"new Font()));
table.AddCell(phrase);
A
PdfPCell
is an object to which you can add different objects, such as
Phrase
s,
Paragraph
s,
Image
s,…
PdfPCell cell = new PdfPCell();
cell.AddElement(new Paragraph("Hello"));
cell.AddElement(list);
cell.AddElement(image);
Inthissnippet
list
isoftype
List
and
image
isoftype
Image
.
The first snippet uses text mode; the second snippet uses composite mode. Cells behave very
differentlydependingonthemodeyouuse.
C# PDF Text Extract Library: extract text content from PDF file in
class. Able to extract and get all and partial text content from PDF file. Ability to extract highlighted text out of PDF document.
cannot save pdf form in reader; export pdf form data to excel spreadsheet
VB.NET PDF Text Extract Library: extract text content from PDF
NET Programming. Extract and get partial and all text content from PDF file. Extract highlighted text out of PDF document. Image text
export pdf data to excel; html form output to pdf
Tables
27
How to introduce a rowspan?
IamaddingatabletoaPDFfile.Ihave3rowsand3columns.Iwantthefirstcolumn
toappearonlyonceasasinglecellforalltherows.Theresultshouldbelikewhere
itsaysDeloitteinthecolumnofcompanyasshownintheimage:
Tableshowingdesiredresult
PostedonStackOverflowonApr5,2014⁴⁵bysindhujampani⁴⁶
TheMyFirstTable⁴⁷examplefrommybookdoesexactlywhatyouneed.PortedtoC#,itlookslike
this:
PdfPTable table = new PdfPTable(3);
// the cell object
PdfPCell cell;
// we add a cell with colspan 3
cell = new PdfPCell(new Phrase("Cell with colspan 3"));
cell.Colspan = 3;
table.AddCell(cell);
// now we add a cell with rowspan 2
cell = new PdfPCell(new Phrase("Cell with rowspan 2"));
cell.Rowspan = 2;
table.AddCell(cell);
// we add the four remaining cells with addCell()
table.AddCell("row 1; cell 1");
table.AddCell("row 1; cell 2");
table.AddCell("row 2; cell 1");
table.AddCell("row 2; cell 2");
⁴⁵
http://stackoverflow.com/questions/22878410/constant-column-for-multiple-rows
⁴⁶
http://stackoverflow.com/users/3191619/sindhu-jampani
⁴⁷
http://itextpdf.com/examples/iia.php?id=75
C# HTML5 PDF Viewer SDK to view PDF document online in C#.NET
Extract Field Data. Data: Auto Fill-in Field Data. Field: Insert VB.NET convert PDF to text, VB.NET extract PDF pages, VB Support to zoom in and zoom out PDF page
extract pdf form data to excel; extract pdf data to excel
VB.NET PDF- View PDF Online with VB.NET HTML5 PDF Viewer
Extract Field Data. Data: Auto Fill-in Field Data. Field: Insert file & pages edit, C#.NET PDF pages extract, copy, paste Support to zoom in and zoom out PDF page
extract data from pdf form to excel; extract data from pdf table
Tables
28
YoucanlookattheresultingPDFhere⁴⁸.Inyourcaseyou’dneed
cell.Rowspan = 6;
ForthecellwithvalueDeloitte.
How to change width of single column of table?
helloIhavecreatedtableinaPDFfileusingiText.Theheadingofmytablecolumnsare
“MedicineName”,“Doses”,and“time:Thisiswhatmycolumnslooklike:
|Medicin|Doses|time|
| e name|
|
|
Asyoucanseetheword“Medicine”issplitinto“Medicin”and“e”.Iwanttoavoidthisby
changingthewidthofthefirstcolumn,butIdon’tknowhowtodothat.
PostedonStackOverflowonJun10,2014⁴⁹byDCoder⁵⁰
TheColumnWidths⁵¹exampledemonstratesdifferentwaysofchangingthewidthofacolumn.This
isonespecificway:
PdfPTable table new PdfPTable(3);
table.setWidths(new int[]{2, 1, , 1});
Nowthewidthofthefirstcolumnisdoublethesizeofthesecondandthirdcolumn.
⁴⁸
http://examples.itextpdf.com/results/part1/chapter04/first_table.pdf
⁴⁹
http://stackoverflow.com/questions/24141791/how-to-change-width-of-single-coloumn-of-table-itext-android
⁵⁰
http://stackoverflow.com/users/2843856/dcoder
⁵¹
http://itextpdf.com/examples/iia.php?id=76
C# PDF Form Data fill-in Library: auto fill-in PDF form data in C#
Able to fill out all PDF form field in C# RasterEdge XDoc.PDF SDK package provides PDF field processing features for will learn how to fill-in field data to PDF
exporting pdf data to excel; c# read pdf form fields
C# WPF PDF Viewer SDK to view PDF document in C#.NET
Extract Field Data. Data: Auto Fill-in Field Data. Field: Insert & pages edit, C#.NET PDF pages extract, copy, paste, C# Abilities to zoom in and zoom out PDF page
how to save pdf form data in reader; pdf form save in reader
Tables
29
What is the
PdfPTable.DefaultCell
property used
for?
What is the
DefaultCell
property used for? The Java documentation for
PdfPTable.getDefaultCell()
reads:
Getsthedefault
PdfPCell
thatwillbeusedasreferenceforallthe
addCell
methodsexcept
addCell(PdfPCell)
.
Idon’tunderstandthis.
PostedonStackOverflowonJun3,2014⁵²byWaterCoolerv2⁵³
Whencreatinga
PdfPTable
,youaddcells.
Onewayistocreatea
PdfPCell
objectandtoaddthatcellwiththe
addCell()
method.
Anotherwayistouseashort-cut:youdon’tcreatea
PdfPCell
,butyouadda
String
ora
Phrase
tothetablewiththe
addCell()
method.Inthiscase,a
PdfPCell
iscreatedinternallyusingdefault
properties.Youcanchangethedefaultpropertiesbychangingthepropertiesofthedefaultcell.
Thedefaultcellisobtainedusingthe
getDefaultCell()
method.
This is what the Javadoc information is about: this default
PdfPCell
will be used as reference
forallthe
addCell()
methodsexcept
addCell(PdfPCell)
.(Becausewhenaddinga
PdfPCell
,the
propertiesofthat
PdfPCell
willbeused,notthepropertiesofthedefaultcell.)
How to draw a borderless table in iTextSharp?
It appearsasthough the
PDfPCell
class does have a border property on itbut not the
PdfPTable
class.
Istheresomepropertyonthe
PdfPTable
classtosetthebordersofallitscontainedcellsin
onestatement?
PostedonStackOverflowonJun3,2014⁵⁴byWaterCoolerv2⁵⁵
Bordersaredefinedatthelevelofthecell,notatthelevelofthetable.Hence:ifyouwanttoremove
thebordersofthetable,youneedtoremovethebordersofeachcell.
⁵²
http://stackoverflow.com/questions/24006618/what-is-the-pdfptable-defaultcell-property-used-for
⁵³
http://stackoverflow.com/users/303685/water-cooler-v2
⁵⁴
http://stackoverflow.com/questions/24006547/draw-a-borderless-table-in-itextsharp
⁵⁵
http://stackoverflow.com/users/303685/water-cooler-v2
VB.NET PDF - View PDF with WPF PDF Viewer for VB.NET
Extract Field Data. Data: Auto Fill-in Field Data. Field: Insert & pages edit, C#.NET PDF pages extract, copy, paste, C# Abilities to zoom in and zoom out PDF page
how to save filled out pdf form in reader; pdf data extraction to excel
VB.NET PDF- HTML5 PDF Viewer for VB.NET Project
Extract Field Data. Data: Auto Fill-in Field Data. Field: Insert VB.NET convert PDF to text, VB.NET extract PDF pages, VB PDF page and zoom in or zoom out PDF page
how to save a pdf form in reader; pdf form field recognition
Tables
30
Bydefault,eachcellhasaborder.Youcanchangethisdefaultbehaviorbychangingtheborderof
eachcell.Forinstance:ifyoucreate
PdfPCell
objects,youuse:
cell.setBorder(Rectangle.NO_BORDER);
Incasethecellsarecreatedinternally,youneedtochangethatpropertyatthelevelofthedefault
cell.
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
Forspecialborders,forinstanceborderswithroundedcornersorasingleborderforthewholetable,
ordoubleborders,youcanuseeithercelleventsortableevents,oracombinationofboth.
Why doesn’t
getDefaultCell()
.setBorder(PdfPCell.NO_BORDER)
have any effect?
I’m new with iText and I’m trying to build a table. For some reason
table.getDefaultCell().setBorder(PdfPCell.NO_BORDER)
has no effect: my table
hasstillborders.
Hereismycode:
PdfPTable table new PdfPTable(new float[] { { 1, 1, , 1, 1, , 1 1 });
table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
Font tfont new Font(Font.FontFamily.UNDEFINED, 10, Font.BOLD);
table.setWidthPercentage(100);
PdfPCell cell;
cell new PdfPCell(new Phrase("Menge", tfont));
table.addCell(cell);
cell new PdfPCell(new Phrase("Beschreibung", tfont));
table.addCell(cell);
cell new PdfPCell(new Phrase("Einzelpreis", tfont));
table.addCell(cell);
cell new PdfPCell(new Phrase("Gesamtpreis", tfont));
table.addCell(cell);
cell new PdfPCell(new Phrase("MwSt", tfont));
table.addCell(cell);
document.add(table);
DoyouhaveanyideawhatIamdoingwrong?
PostedonStackOverflowonNov30,2014⁵⁶byhiasl⁵⁷
⁵⁶
http://stackoverflow.com/questions/27212695/itext-5-getdefaultcell-setborderpdfpcell-no-border-has-no-effect
⁵⁷
http://stackoverflow.com/users/4308508/hiasl
VB.NET PDF - WPF PDF Viewer for VB.NET Program
Field Data. Data: Auto Fill-in Field Data. Field: Insert & pages edit, C#.NET PDF pages extract, copy, paste rotate PDF pages, zoom in or zoom out PDF pages and go
pdf data extraction; extract data from pdf c#
VB.NET PDF File & Page Process Library SDK for vb.net, ASP.NET
Moreover, when you get a PDF document which is out of order, you need to adding a page into PDF document, deleting unnecessary page from PDF file and changing
extract table data from pdf; how to fill in a pdf form in reader
Tables
31
Youaremixingtwodifferentconcepts.
Concept1:youdefineevery
PdfPCell
manually,forinstance:
PdfPCell cell new PdfPCell(new Phrase("Menge", tfont));
cell.setBorder(Rectangle.NO_BORDER);
table.addCell(cell);
Inthiscase,youdefineeveryaspect,everypropertyofthecellonthecellitself.
Concept2:youallowiTexttocreatethe
PdfPCell
implicitly,forinstance:
table.addCell("Adding a String");
table.addCell(new Phrase("Adding a phrase"));
Inthiscase,youcandefinepropertiesatthelevelofthedefaultcell.Thesepropertieswillbeused
internallywheniTextcreatesa
PdfPCell
inyourplace.
Conclusion:eitheryoudefinetheborderforallthe
PdfPCell
instancesseparately,oryouletiText
createthe
PdfPCell
instancesinwhichcaseyoucandefinetheborderatthelevelofthedefaultcell.
Ifyouchoosethesecondoption,youcanadaptyourcodelikethis:
PdfPTable table new PdfPTable(new float[] { { 1, , 1, , 1, 1, 1 });
table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
Font tfont new Font(Font.FontFamily.UNDEFINED, 10, Font.BOLD);
table.setWidthPercentage(100);
table.addCell(new Phrase("Menge", tfont));
table.addCell(new Phrase("Beschreibung", tfont));
table.addCell(new Phrase("Einzelpreis", tfont));
table.addCell(new Phrase("Gesamtpreis", tfont));
table.addCell(new Phrase("MwSt", tfont));
document.add(table);
Thisdecisionwasmadebydesign,basedonexperience:itoffersthemostflexibletoworkwithcells
andproperties.
Table events
Wecontinuewithsomequestionsabouttablesofwhichtheanswerinvolvestableorcellevents.
How to use adotted line as a cell border?
Iamtryingtocreateatablewithcellsthathaveadottedlineforaborder.HowcanIdo
this?
PostedonStackOverflowonNov21,2013⁵⁸withuser1913695⁵⁹
I’vemadeanexamplethatsolvesyourproblem:DottedLineCell⁶⁰;TheresultingPDFisadocument
withtwotables:dotted_line_cell.pdf⁶¹
Forthefirsttable,weuseatableevent:
class DottedCells implements PdfPTableEvent {
@Override
public void tableLayout(PdfPTable tablefloat[][] widths,
float[] heights, int headerRows, int rowStart,
PdfContentByte[] canvases) {
PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
canvas.setLineDash(3f, 3f);
float llx widths[0][0];
float urx widths[0][widths[0].length -1];
for (int = 0; heights.lengthi++) {
canvas.moveTo(llx, heights[i]);
canvas.lineTo(urx, heights[i]);
}
for (int = 0; widths.lengthi++) {
for (int = 0; widths[i].lengthj++) {
canvas.moveTo(widths[i][j], heights[i]);
canvas.lineTo(widths[i][j], heights[i+1]);
}
⁵⁸
http://stackoverflow.com/questions/20117321/dotted-line-for-cell-border
⁵⁹
http://stackoverflow.com/users/1913695/user1913695
⁶⁰
http://itextpdf.com/sandbox/tables/DottedLineCell
⁶¹
http://itextpdf.com/sites/default/files/dotted_line_cell.pdf
Tableevents
33
}
canvas.stroke();
}
}
Thisisthemostelegantwaytodrawthecellborders,asitusesonlyone
stroke()
operatorforall
thelines.Unfortunately,thissolutionisn’tanoptionifyouhavetableswithrowspans.
Thesecondtableusesacellevent:
class DottedCell implements PdfPCellEvent {
@Override
public void cellLayout(PdfPCell cellRectangle position,
PdfContentByte[] canvases) {
PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
canvas.setLineDash(3f, 3f);
canvas.rectangle(position.getLeft(), position.getBottom(),
position.getWidth(), position.getHeight());
canvas.stroke();
}
}
Withacellevent,aborderisdrawnaroundeverycell.Thismeansyou’llhavemultiple
stroke()
operatorsandoverlappinglines.However:thissolutionalwaysworks,alsowhenthetablehascells
witharowspangreaterthanone.
How to create atable with rounded corners?
Ihavetocreateatablehavingroundedcorners,somethinglikeit:
Cellwithroundedborder
CanIdoitwithiTextSharp?
PostedonStackOverflowonMay14,2014⁶²byAndreaNobili⁶³
⁶²
http://stackoverflow.com/questions/23650957/how-to-create-a-rounded-corner-table-using-itext-itextsharp
⁶³
http://stackoverflow.com/users/1833945/andreanobili
Tableevents
34
Thisisdoneusingcellevents.
Makesurethatyoudon’taddany“automated”borderstothecell,butdrawthebordersyourselfin
acellevent:
table.DefaultCell.Border = PdfPCell.NO_BORDER;
table.DefaultCell.CellEvent = new RoundedBorder();
The
RoundedBorder
classwouldthenlooklikethis:
class RoundedBorder : IPdfPCellEvent {
public void CellLayout(PdfPCell cell, , Rectangle rect, PdfContentByte[] canvas)\
{
PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
cb.RoundRectangle(
rect.Left + 1.5f,
rect.Bottom + 1.5f,
rect.Width - 3,
rect.Height - 34
);
cb.Stroke();
}
}
Youcanofcoursefine-tunethevalues1.5,3and4togetdifferenteffects.
Documents you may be interested
Documents you may be interested