Re: How to limit memory usage when extracting text from large PDFs?
Accented Characters in PDF Files
class Program { static void Main(string[] args) { string testStr = "Książęce"; System.IO.File.WriteAllBytes("TestFile.pdf", SavePdf(testStr)); } /// <summary> /// Saves the PDF. /// </summary> /// <param name="inputHtml">The input HTML.</param> /// <returns>A byte array representing the generated PDF</returns> public static byte[] SavePdf(string inputHtml) { Pdf pdf = new Pdf(); Section section = pdf.Sections.Add(); section.PageInfo.Margin.Top = 5; section.PageInfo.Margin.Left = 5; section.PageInfo.Margin.Bottom = 5; section.PageInfo.Margin.Right = 5; section.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A4Height; section.PageInfo.PageWidth = Aspose.Pdf.Generator.PageSize.A4Width; Text text = new Text(section, inputHtml); text.IsHtmlTagSupported = true; section.Paragraphs.Add(text); text.IsFitToPage = true; byte[] pdfBytes; using (MemoryStream s = new MemoryStream()) { pdf.Save(s); pdfBytes = s.ToArray(); } return pdfBytes; } }
Remove Image Stamp from PDF
Hi Team,
I have a requirement to add a QR code on PDF and later on it should be removed from the file.
So I use below code to add the QR code image in to PDF.
//Open documentDocument pdfDocument = new Document("input.pdf");
//Create image stampImageStamp imageStamp = new ImageStamp("aspose-logo.jpg");
imageStamp.Background = true;
imageStamp.XIndent = 100;
imageStamp.YIndent = 100;
imageStamp.Height = 300;
imageStamp.Width = 300;
imageStamp.Rotate = Rotation.on270;
imageStamp.Opacity = 0.5;
//Add stamp to particular pagepdfDocument.Pages[1].AddStamp(imageStamp);
//Save output documentpdfDocument.Save("output.pdf");
Now I want to remove the image stamps that I have added. How can I remove the image stamps from PDF?
need support about aspose pdf
This message was posted using Banckle Live Chat 2 Forum
PDF password protection not working
I an using the PDF password protect API but when I open the PDF file
the OWNER and USER see the same menu options
- what i mean is that the OWN also see the menu options disabled.
here's the code I am using...
Aspose.Pdf.Permissions _Permissions = new Aspose.Pdf.Permissions(); // nothing enabled
Aspose.Pdf.CryptoAlgorithm _CryptoAlgorithm = Aspose.Pdf.CryptoAlgorithm.AESx128;
doc.Encrypt(UserPassword,
OwnerPassword,
_Permissions,
_CryptoAlgorithm);
HTML with multibyte characters don't convert to PDF properly
Saving as TIF issue
Code below:
Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document("HelloWorld.pdf");
pdfDoc.Save("HelloWorld.tif");
I am attaching the two files.
Thanks
split pdf file to individual pages get this error - value can not be null in java
Wrong PageInfo for landscape ?
converting text to PDF doesn't finish
Problem signing a PDF file
1 String inFile = TestPath + "example1.pdf"; 2 String outFile = TestPath + "signature.pdf"; 3 PKCS1 sig = new PKCS1("certificate.pfx", "password"); 4 sig.setReason ("Some reason"); 5 sig.setContact ("Smith"); 6 sig.setLocation ("New York"); 7 PdfFileSignature pdfSign = new PdfFileSignature(inFile, outFile); 8 Rectangle rect = new Rectangle(100, 100, 200, 100); 9 pdfSign.setSignatureAppearance ( TestPath + "butterfly.jpg"); 10 pdfSign.sign(2, true, rect, sig); 11 pdfSign.save();
Line 3 does not compile and gives the following error:
- com.aspose.pdf.engine.security cannot be resolved to a type - The type com.aspose.pdf.b.d cannot be resolved. It is indirectly referenced from required .class files
How to according to the number of PDF pages to convert.
how to add watermark with rotate 45 to pdf (aspose java)
Using custom font from custom folder in generator.pdf
Strange text extracted using TextAbsorber
PDF convert to HTML - some words overlap
Convert PDF to TIFF
We are trying to convert PDF to TIFF. If the PDF is just text and can be converted using CCITT4 compression the resulting TIFF is fine and easily read. However, if the PDF includes color images and text then the text in the resulting TIFF file cannot be easily read and the size of the file is large. I am using the following which is from another forum post.
//create PdfConverter object and bind input PDF file
Aspose.Pdf.Facades.PdfConverter pdfConverter = new Aspose.Pdf.Facades.PdfConverter();
// create Resolution object with 300 as an argument
Aspose.Pdf.Devices.Resolution resolution = new Aspose.Pdf.Devices.Resolution(SetSaveOptionResolution());
// specify the resolution value for PdfConverter object - default is 150
pdfConverter.Resolution = resolution;
// bind the source PDF file
pdfConverter.BindPdf(cnvFileData.CnvFileName);
// start the conversion process
pdfConverter.DoConvert();
//create TiffSettings object, set Compression and ColorDepth
Aspose.Pdf.Devices.TiffSettings tiffSettings = new Aspose.Pdf.Devices.TiffSettings();
if (BlackAndWhite ||
CheckOverrideCompression(fileExt) ||
Compression.Equals("Group4FaxEncoding", StringComparison.CurrentCultureIgnoreCase))
tiffSettings.Compression = Aspose.Pdf.Devices.CompressionType.CCITT4;
else
tiffSettings.Compression = Aspose.Pdf.Devices.CompressionType.LZW;
retFileName = System.IO.Path.ChangeExtension(cnvFileData.CnvFileName, format.ToLower());
pdfConverter.SaveAsTIFF(retFileName, tiffSettings);
pdfConverter.Close();
//create PdfConverter object and bind input PDF file
Aspose.Pdf.Facades.PdfConverter pdfConverter = new Aspose.Pdf.Facades.PdfConverter();
// create Resolution object with 300 as an argument
Aspose.Pdf.Devices.Resolution resolution = new Aspose.Pdf.Devices.Resolution(SetSaveOptionResolution());
// specify the resolution value for PdfConverter object - default is 150
pdfConverter.Resolution = resolution;
// bind the source PDF file
pdfConverter.BindPdf(cnvFileData.CnvFileName);
// start the conversion process
pdfConverter.DoConvert();
//create TiffSettings object, set Compression and ColorDepth
Aspose.Pdf.Devices.TiffSettings tiffSettings = new Aspose.Pdf.Devices.TiffSettings();
if (BlackAndWhite ||
CheckOverrideCompression(fileExt) ||
Compression.Equals("Group4FaxEncoding", StringComparison.CurrentCultureIgnoreCase))
tiffSettings.Compression = Aspose.Pdf.Devices.CompressionType.CCITT4;
else
tiffSettings.Compression = Aspose.Pdf.Devices.CompressionType.LZW;
retFileName = System.IO.Path.ChangeExtension(cnvFileData.CnvFileName, format.ToLower());
pdfConverter.SaveAsTIFF(retFileName, tiffSettings);
pdfConverter.Close();
This is being done in a console app or service. Are there settings that will give better results for color both file size and legibility of text? Can we query attributes of the PDF in order to make better decision on the compression and resolution? For instance if the PDF is all text but saved as color can we determine that it is all text and can be saved as CCITT4.
File to be converted is attached.
Insert image into PDF at specified coordinates - placement, scaling?
I need to insert an image of (PNG or JPEG) at specific coordinates of a page in the PDF file.
The web application gets the file from the document library and renders it into individual PNG files using this method http://www.aspose.com/docs/display/pdfnet/Convert+PDF+pages+to+JPEG+images, like that:
// Open PDF file
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(inputFilePath);
// Measure it
int pageCount = pdfDocument.Pages.Count;
try
{
for (int pageNumber = 1; pageNumber
{
string pageName = String.Format("Page{0}.png", pageNumber);
string pagePath = Path.Combine(dataDirectory, pageName);
using (FileStream imageStream = new FileStream(pagePath, FileMode.Create))
{
//create PNG device with specified attributes
//Width, Height, Resolution, Quality
//Quality [0-100], 100 is Maximum
//create Resolution object
Resolution resolution = new Resolution(100);
PngDevice pngDevice = new PngDevice(new PageSize(PageSize.A4.Width, PageSize.A4.Height), resolution);
//convert a particular page and save the image to stream
pngDevice.Process(pdfDocument.Pages[pageNumber], imageStream);
//close stream
imageStream.Close();
}
}
}
catch (IndexOutOfRangeException ex)
{
if (ex.Source == "Aspose.Pdf")
{
// At most 4 elements (for any collection) can be viewed in evaluation mode.
// Eval mode in Aspose throws it
Logger.Instance.Log(Logger.SERVICE_TRACE_SOURCE, System.Diagnostics.TraceEventType.Error, String.Format(
"DocumentManager.convertPDFFileToPageImages: Aspose.Pdf in evaluation mode"));
}
else
{
throw;
}
}
User reviews the pages in the web browser, and clicks where they want the image to be inserted.
Then, I use method described here http://www.aspose.com/docs/display/pdfnet/Add+Image+in+existing+PDF+file to add an image at the specified location, like that
// For each image selected
foreach (ImageLocation imageLocation in imageLocations)
{
// Add images to the right pages
Page page = pdfDocument.Pages[imageLocation.PageNumber];
using (FileStream imageStream = new FileStream(imageLocation.FilePath, FileMode.Open))
{
page.Resources.Images.Add(imageStream);
}
XImage xImage = page.Resources.Images[page.Resources.Images.Count];
Logger.Instance.Log(Logger.SERVICE_TRACE_SOURCE, System.Diagnostics.TraceEventType.Verbose, String.Format(
"DocumentManager.InsertImagesIntoFileInStorage: Added '{0}' file to '{1}' page as XImage.Name='{2}', width='{3}', height='{4}''",
imageLocation.FilePath,
imageLocation.PageNumber,
xImage.Name,
xImage.Width,
xImage.Height));
// Insert images into right location
//using GSave operator: this operator saves current graphics state
page.Contents.Add(new Operator.GSave());
//create Rectangle and Matrix objects
Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(imageLocation.XPosition, imageLocation.YPosition, imageLocation.XPosition + xImage.Width, imageLocation.YPosition + xImage.Height);
Aspose.Pdf.DOM.Matrix matrix = new Aspose.Pdf.DOM.Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });
//using ConcatenateMatrix (concatenate matrix) operator: defines how image must be placed
page.Contents.Add(new Operator.ConcatenateMatrix(matrix));
//using Do operator: this operator draws image
page.Contents.Add(new Operator.Do(xImage.Name));
//using GRestore operator: this operator restores graphics state
page.Contents.Add(new Operator.GRestore());
}
I am having difficulty in placing the image at exact location I specified and having it be the same size I specified.
Attached is the document. It already contained a 100x100 PNG with yellow background and "2" upside down in the bottom-right corner, at the bottom left of the first page.
The user inserted 100x100 PNG with orange background and "1" proper way up in the upper left corner at x=74 and y=176 coordinates as measured from bottom left of the page, just above the original image and aligned to it's left side
Added 'D:\Projects\
Aspose.Pdf.Rectangle LLX='74', LLY='176', URX='174', URY='276', Width='100', Height='100'
Aspose.Pdf.DOM.Matrix A='100', B='0', C='0', D='100', E='74', F='176'
The original image measures 1.04" in size (as it was when I inserted it.
The second image is displayed visually offset from where I want it to. It also measures 1.78" in size, and 1.04/1.78 happens to be pretty close to 0.75% which makes me think some sort of scaling going on
Question: How do I insert the image at the right location and scale in the page?
I am using Aspose.PDF 9.1.0.0.
Thank you